package malagaAcoge.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JPAUtils {
	private static final String PERSISTENCE_UNIT_NAME = "pfcmalagaacoge";
	private static EntityManagerFactory factory;
	protected EntityManager em;

	public EntityManager getEntityManager() {
		try {
			factory = Persistence
					.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
			em = factory.createEntityManager();
		} catch (Exception e) {
			System.err.println("Error inicializando entityManager.");
			e.printStackTrace();
		}
		return em;
	}
}
